package com.ydy.file.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class FileInterceptorConfig implements WebMvcConfigurer {

    /**
     * 上传的图片在F盘下的file目录下，访问路径如：http://localhost:8080/file/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
     *  其中file表示访问的前缀。"file:F:/file/"是文件真实的存储路径
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //图片
        registry.addResourceHandler("/image/**").
                addResourceLocations("file:/image/");
        //pdf文件
        registry.addResourceHandler("/pdf/**").
                addResourceLocations("file:/pdf/");
        //视屏
        registry.addResourceHandler("/video/**").
                addResourceLocations("file:/video/");
        //word文件
        registry.addResourceHandler("/word/**").
                addResourceLocations("file:/word/");
        //excel文件
        registry.addResourceHandler("/excel/**").
                addResourceLocations("file:/excel/");
    }
}